package com.xiaoma.tpo.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.xiaoma.tpo.baseDao.BaseDaoImpl;
import com.xiaoma.tpo.baseDao.DefaultRowMapper;
import com.xiaoma.tpo.domain.UserListeningRecording;

@Repository
public class UserListeningRecordingDao extends BaseDaoImpl<UserListeningRecording>{

    @SuppressWarnings("unchecked")
    public List<UserListeningRecording> get7DaysRecords(int userId, String date) {
        String sql = "SELECT * FROM user_listening_recording where user_id = ? and date > ? ORDER BY type asc, date asc";
        List<?> result = jdbcTemplate.query(sql, new DefaultRowMapper(UserListeningRecording.class, getNameHandler()), userId, date);
        return (List<UserListeningRecording>)result;
    }
    
    public int getUserListeningRecordingTotalCount(int userId, int type) {
        String sql = "SELECT sum(count) FROM user_listening_recording where user_id = ? and type = ?";
        return jdbcTemplate.queryForInt(sql, userId, type);
    }
}
